package com.zengdada.authority.mapper;

import com.zengdada.authority.utils.where.result.MapperAnalysisResultMerge;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @Auther: 12614
 * @Contact: 1261438511@qq.com
 * @Date: 2018/12/12 20:45
 * @Description:
 */
public interface PublicSqlMapper {

//    @Select("<script>select <if test=\"null == fields or fields.size == 0\"> * </if><foreach collection=\"fields\" item=\"field\" open=\"\" separator=\",\" close=\"\"> ${field}</foreach> from (${searchSql}) SELECT_TMP " +
//            "<if test=\"null != params\"><foreach collection=\"params\" item=\"param\" open=\" where \" separator=\"and\" close=\"\">" +
//            " ${param.conditionAndPrefix} <if test=\"param.conditionVal!=null\">" +
//            "   <if test=\"!(param.conditionVal instanceof java.util.List) and !(param.conditionVal instanceof com.zengdada.authority.utils.PublicSearchRangeAssist)\">#{param.conditionVal}</if>" +
//            "   <if test=\"param.conditionVal instanceof java.util.List\"><foreach collection=\"param.conditionVal\" item=\"item\" open=\"\" separator=\",\" close=\"\">#{item}</foreach></if>" +
//            "   <if test=\"param.conditionVal instanceof com.zengdada.authority.utils.PublicSearchRangeAssist\"> #{param.conditionVal.front} AND #{param.conditionVal.after} </if>" +
//            "</if> ${param.conditionSuffix} " +
//            "</foreach></if>" +
//            "<if test=\"sort!=null\"> order by ${sort}</if></script>")
//    List<Map<String, Object>> selectData(@Param("fields") List<String> fields, @Param("searchSql") String rawdml, @Param("params") List<PublicSearch> params, @Param("sort") String sort);

    @Select("select * from (${sql}) where rownum = 1")
    Map<String, Object> selectOneBySQL(@Param("sql") String sql);


    @Select("select * from (${searchSql})")
    List<Map<String, Object>> selectDataSimple(@Param("searchSql") String rawdml);

    @Select("<script>select <if test=\"null == fields or fields.size == 0\"> * </if><foreach collection=\"fields\" item=\"field\" open=\"\" separator=\",\" close=\"\"> ${field}</foreach> from (${searchSql}) tmp " +
            "<if test=\"null != where and where.isNull != true\"> where ${where.extraFilter}</if>" +
            "<if test=\"sort!=null\"> order by ${sort}</if></script>")
    List<Map<String, Object>> selectDataEnhance(@Param("fields") List<String> fields, @Param("searchSql") String rawdml, @Param("where") MapperAnalysisResultMerge where, @Param("sort") String sort);

}
